<?php
namespace App\Common\Lib\Cache\KeyDB;

use App\Common as com;
use App\Common\Lib\Cache\KeyDB;

/**
 * @property com\Cla\ClaBase\DataStore $dataStore
 */
class Base extends com\Cla\ClaBase\CommonOfId\Main {

	protected string $keyPath;

	protected array $param = [];

	protected string $_hyPackTag = '_hyPack:';

	protected int $_hyPackTagLength = 8;

	/**
	 * DbBase constructor.
	 * @param string $keyPath key路径数据。[{array}]多个路径
	 * @param array $param
	 */
	public function __construct( string $keyPath, array $param = [] ) {
		$this->keyPath = $keyPath;
		//
		if( ! empty( $param ) ){
			$this->param( ...$param );
		}
		//
		parent::__construct();
	}

	/**
	 * @return $this
	 */
	public function newOfClone(  ):self {
		return new static( $this->keyPath, $this->getParam() );
	}

	/**
	 * 附加key地址
	 * @param string $keyPath
	 * @return $this
	 */
	public function appendkeyPath( string $keyPath ):self {
		$this->keyPath[] = $keyPath;
		return $this;
	}

	/**
	 * 获取缓存键参数
	 * @return array
	 */
	public function getParam():array {
		return $this->param;
	}

	/**
	 * 设置缓存键参数
	 * @param mixed ...$args
	 * @return $this
	 */
	public function param( ...$args ):self {
		$this->param = $args;
		return $this;
	}

	// ===============================
	//
	//
	// 下面为静态方法
	//
	//
	// ===============================

	/**
	 * @param string $keyPath 缓存路径
	 * @return $this
	 */
	public static function newOfKeyPath( string $keyPath = null ):self {
		return new static( $keyPath ?? '' );
	}

	/**
	 * @param string $keyPath 缓存路径
	 * @return $this
	 */
	public static function use( string $keyPath = null ):self {
		return new static( $keyPath ?? '' );
	}

}
